/*
 * UserNet  --  TCP/IP implementation in userspace
 * Copyright (C) 2010  Alex Diban
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef UNET_IP_H
#define UNET_IP_H

#include <stdint.h>
#include <netinet/ip.h>		/* IP_MAXPACKET, needed by callers */
#include <netinet/in.h>		/* struct in_addr */

#include "unet/dev.h"
#include "unet/tcp.h"
#include "unet/ether.h"
#include "unet/udp.h"

#define IP_HEADER_SIZE 5	//Ip header size in 32 bit word

enum ip_protocols
  {
    UNET_TCP,
    UNET_UDP,
    UNET_ICMP
  };

struct unet_ip_packet {
  struct iphdr header;  
  uint8_t payload[0];
};

#ifdef _UNET_CLIENT
/* For the client.  */
//Desde IP --> TCP/UDP
extern void unet_ip_incoming_packet (const uint8_t *packet, const uint32_t len);
//Desde TCP/UDP --> IP
extern int unet_transport_send_packet(enum ip_protocols type,struct in_addr ip_addr,void * buff,size_t len);
#endif

#ifdef _UNET_SERVER
/* For the server.  */
extern void unet_ip_incoming_packet (struct unet_device *ud, const uint8_t *packet, const uint32_t len);
extern void unet_ip_send_packet (const uint8_t *packet, const uint32_t len);
extern void unet_ip_icmp_send_packet(struct in_addr ip_addr,void * buff,size_t len);
#endif

#endif
